﻿using Abp.AspNetCore;
using Abp.Configuration.Startup;
using Abp.Modules;
using Abp.Reflection.Extensions;
using AbpIntegrationDemo.Application;
using AbpIntegrationDemo.Domain;
using AbpIntegrationDemo.Infrastructure;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Extensions.Configuration;

namespace AbpIntegrationDemo.Admin
{
[DependsOn(
    typeof(AbpIntegrationApplicationModule),
    typeof(AbpIntegrationInfrastructureModule),
    typeof(AbpAspNetCoreModule)
    )]
public class AbpIntegrationAdminModule : AbpModule
{
    private readonly IWebHostEnvironment _env;
    private readonly IConfiguration _appConfiguration;

    public AbpIntegrationAdminModule(IWebHostEnvironment env, IConfiguration appConfiguration)
    {
        _env = env;
        _appConfiguration = appConfiguration;
    }

    public override void PreInitialize()
    {
        Configuration.DefaultNameOrConnectionString = _appConfiguration.GetConnectionString(AbpIntegrationDomainConsts.ConnectionStringName);
        Configuration.Modules.AbpWebCommon().SendAllExceptionsToClients = false;
    }

    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(typeof(AbpIntegrationAdminModule).GetAssembly());
    }

    public override void PostInitialize()
    {
        IocManager.Resolve<ApplicationPartManager>()
            .AddApplicationPartsIfNotAddedBefore(typeof(AbpIntegrationAdminModule).Assembly);
    }

    public override void Shutdown()
    {
        base.Shutdown();
    }
}
}
